<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>余额充值</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            margin: 20px;
        }
        .container {
            max-width: 400px;
            margin: 0 auto;
            padding: 20px;
            border: 1px solid #ccc;
            border-radius: 5px;
            background-color: #f9f9f9;
        }
        h1 {
            text-align: center;
            color: #333;
        }
        .balance {
            font-size: 18px;
            font-weight: bold;
            text-align: center;
            margin-bottom: 20px;
        }
        .recharge-section {
            margin-bottom: 20px;
        }
        .recharge-section label {
            display: block;
            margin-bottom: 10px;
            font-weight: bold;
        }
        .recharge-section input {
            width: 90%;
            padding: 10px;
            font-size: 16px;
            border: 1px solid #ccc;
            border-radius: 5px;
        }
        .recharge-btn {
            display: block;
            width: 100%;
            padding: 10px;
            background-color: #28a745;
            color: white;
            border: none;
            border-radius: 5px;
            font-size: 16px;
            cursor: pointer;
        }
        .recharge-btn:hover {
            background-color: #218838;
        }
        .error-message {
            color: red;
            font-size: 14px;
            text-align: center;
            margin-top: 10px;
            display: none;
        }
    </style>
</head>
<body>
<div class="container">
    <h1>余额充值</h1>
    <div class="balance">
        当前余额：<span id="now">100</span> 元
    </div>
    <div class="recharge-section">
        <label for="money">充值金额：</label>
        <input type="text" id="money" placeholder="请输入充值金额" >
    </div>
    <button class="recharge-btn" onclick="recharge()">充值</button>
    <div id="errorMessage" class="error-message">充值金额必须大于1元！</div>
</div>

<script>
    // 当前余额（示例数据）
    let now = 100;

    // 充值功能
    function recharge() {
        const money = document.getElementById('rechargeAmount').value;
        const errorMessage = document.getElementById('errorMessage');

        // 校验充值金额
        if (!money || isNaN(money)){
            errorMessage.textContent = '请输入有效的充值金额！';
            errorMessage.style.display = 'block';
            return;
        }

        const amount = parseInt(money);
        if (amount <= 1 || !Number.isInteger(amount)) {
            errorMessage.textContent = '充值金额必须大于1元！';
            errorMessage.style.display = 'block';
            return;
        }

        // 充值成功
        errorMessage.style.display = 'none';
        now += amount;
        document.getElementById('now').textContent = now;
        alert('充值成功！当前余额：' + now + ' 元');
    }
</script>
</body>
</html>